package com.zink.ezequiel.codes.data;

import android.content.Context;
import com.desandroid.framework.ada.ObjectContext;
import com.desandroid.framework.ada.ObjectSet;
import com.desandroid.framework.ada.exceptions.AdaFrameworkException;
import com.zink.ezequiel.codes.data.model.Entry;
import com.zink.ezequiel.codes.data.model.Tag;

public class ApplicationDataContext extends ObjectContext {

    public static final int DATABASE_VERSION = 1;
    /**
     * Database file name.
     */
    public static final String DATABASE_NAME = "codes.db";

    private ObjectSet<Entry> entriesSet;

    private ObjectSet<Tag> tagsSet;

    public ApplicationDataContext(Context pContext) throws AdaFrameworkException {
        super(pContext, DATABASE_NAME, DATABASE_VERSION);
        if (entriesSet == null) {
        	entriesSet = new ObjectSet<Entry>(Entry.class, this);
        }
        if (tagsSet == null) {
        	tagsSet = new ObjectSet<Tag>(Tag.class, this);
        }
    }

    public ObjectSet<Entry> getEntriesSet() {
        return entriesSet;
    }

    public ObjectSet<Tag> getTagsSet() {
        return tagsSet;
    }
    
    public boolean isSongListLoaded() throws AdaFrameworkException {
        boolean result = true;
        entriesSet.fill();
        if (entriesSet.isEmpty()) {
            result = false;
        }
        return result;
    }
}